import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    redirect:'/home'
  },
  {
    path:"/login",name:'login',component:()=>import('../views/loginView.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
    redirect:'/home/workbench',
    children:[
      {path:'workbench',name:'workbench',component:()=>import('../components/backend/xsg/workbench.vue')},
      {path:'memberfiles',name:'memberfiles',component:()=>import('../components/backend//xsg/Member.vue')},
      {path:'physicalexamination',name:'physicalexamination',component:()=>import('../components/backend/xsg/physical.vue')},
      {path:'Membership',name:'Membership',component:()=>import('../components/backend/xsg/Membership.vue')},
      {path:'Healthy',name:'Healthy',component:()=>import('../components/HealthyMRD.vue')},
      {path:'user',name:'user',component:()=>import('../components/backend/xsg/User.vue')},
      //刘成杰预约管理Vue
      {path:'Subscribe',name:'Subscribe',component:()=>import('../components/backend/liuchengjie/Booking Management/Subscribe.vue')},
      {path:'Appointmentsetting',name:'Appointmentsetting',component:()=>import('../components/backend/liuchengjie/Booking Management/Appointmentsetting.vue')},
      {path:'setmeal',name:'setmeal',component:()=>import('../components/backend/liuchengjie/Booking Management/Setmeal.vue')},
      {path:'Examinationitems',name:'Examinationitems',component:()=>import('../components/backend/liuchengjie/Booking Management/Examinationitems.vue')},
      //刘成杰知识库VUe
      {path:'pgjy',name:'pgjy',component:()=>import('../components/backend/liuchengjie/zhishiku/PingGujianyi.vue')},
      {path:'jkfa',name:'jkfa',component:()=>import('../components/backend/liuchengjie/zhishiku/Jiankangfangan.vue')},
      {path:'ydxmk',name:'ydxmk',component:()=>import('../components/backend/liuchengjie/zhishiku/YunDongXinag.vue')},
      {path:'ssk',name:'ssk',component:()=>import('../components/backend/liuchengjie/zhishiku/ShanShiku.vue')},
      {path:'jbk',name:'jbk',component:()=>import('../components/backend/liuchengjie/zhishiku/JiBingku.vue')},
      {path:'tjfx',name:'tjfx',component:()=>import('../components/backend/liuchengjie/zhishiku/tongjifenxi.vue')},
      //罗庆
      {path:'health',name:'health',component:()=>import('../components/backend/luoqing/Health.vue')},
      {path:'psychometric',name:'psychometric',component:()=>import('../components/backend/luoqing/Psychometric.vue')},
      {path:'risk',name:'risk',component:()=>import('../components/backend/luoqing/risk.vue')},
      {path:'follow',name:'follow',component:()=>import('../components/backend/luoqing/JianKangGanyu/Follow-up.vue')},
      {path:'indicator',name:'indicator',component:()=>import('../components/backend/luoqing/JianKangGanyu/Indicator Management.vue')},
      {path:'intervention',name:'intervention',component:()=>import('../components/backend/luoqing/JianKangGanyu/Intervention.vue')},
      {path:'muban',name:'muban',component:()=>import('../components/backend/luoqing/JianKangGanyu/mubanManagement.vue')},
      {path:'population',name:'population',component:()=>import('../components/backend/luoqing/JianKangGanyu/Population.vue')},
      {path:'GroupPagingInformation',name:'GroupPagingInformation',component:()=>import('../components/backend/luoqing/JianKangGanyu/GroupPagingInformation.vue')},
      {path:'DecisionMaker',name:'DecisionMaker',component:()=>import('../components/backend/luoqing/JianKangGanyu/DecisionMaker.vue')}
      
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
    let userInfo =  sessionStorage.getItem("user")
    if(!userInfo){
      if(to.path==="/" || to.path==="/login"){
        next()
      }else{
        next({path:'/login'})
      }
    }else{
      next()
    }  
})

//路由后置守卫
router.afterEach((to)=>{
  let menpath=[]
  //如果breadcrunmbName是空的就不需要传递参数
  if(!to.query.breadcrunmbName){
    //调用getbreadcrunmbName方法
    router.app.$store.commit("getbreadcrunmbName")
    //如果不是空
  }else if(to.query.breadcrunmbName.length!=0){
    //根据逗号分割参数
    menpath = to.query.breadcrunmbName.split(",")
    //调用getbreadcrunmbName传参
    router.app.$store.commit("getbreadcrunmbName",menpath)
  }

})

export default router
